package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {


    /**
     * 插入訂單數據
     * @param order
     */
    void submit(Orders order);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select * from orders where id = #{id}")
    Orders getByOrderId(Long id);

//    @Select("select pay_status from orders where user_id = #{userId}")
//    List<Integer> getStatus(Long userId);

    @Select("select count(status)  from orders where status = #{status}")
    Integer getByStatus(Integer deliveryInProgress);

    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> getByStatusAndOrdertimeLT(Integer status, LocalDateTime orderTime);

    /**
     * 根据动态条件统计营业额
     * @param map
     */
    Double getByMap(Map map);


    Integer userStatistics(LocalDateTime beginTime, LocalDateTime endTime);

    Integer getOrderCount(LocalDateTime beginTime, LocalDateTime endTime, Integer status);


    List<OrderDetail> getTop(LocalDateTime begin, LocalDateTime end);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap1(Map map);

    Integer countByMap(Map map);
}
